package cn.cttic.order.mapper;

import cn.cttic.order.api.domain.BaseFilings;
import cn.cttic.order.api.domain.vo.BaseFilingsVo;
import cn.cttic.common.mybatis.core.mapper.BaseMapperPlus;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 备案信息Mapper接口
 *
 * @author Times.Studio
 * @date 2024-09-30
 */
public interface BaseFilingsMapper extends BaseMapperPlus<BaseFilings, BaseFilingsVo> {

    @Select("<script>" +
        "select \n" +
        "	saleOrder.id as saleOrderId,\n" +
        "	installOrder.id as installOrderId,\n" +
        "	saleOrder.last_name as customer_name,\n" +
        "	saleOrder.phone as customer_phone,\n" +
        "	installOrder.car_no as car_no,\n" +
        "	device.device_name as device_name,\n" +
        "	device.device_model as device_model,\n" +
        "	product.product_name as product_name,\n" +
        "	saleChannelDic.dict_label as sale_channel_type_name,\n" +
        "	salesManCompany.company_name as sale_channel_name,\n" +
        "	salesMan.real_name as sales_man_name,\n" +
        "	installChannelDic.dict_label as install_channel_type_name,\n" +
        "	installManCompany.company_name as install_channel_name,\n" +
        "	installMan.real_name as install_man_name,\n" +
        "	installOrder.imei as imei,\n" +
        "	installOrder.online_time as online_time,\n" +
        "	installOrder.last_online_time as last_online_time,\n" +
        "	installOrder.active_time as active_time,\n" +
        "	installOrder.verify_status as verify_status,\n" +
        "	installOrder.verify_time as verify_time,\n" +
        "	installOrder.review_status as review_status,\n" +
        "	installOrder.review_time as review_time,\n" +
        "	installOrder.check_status as check_status,\n" +
        "	installOrder.check_time as check_time\n" +
        "from \n" +
        "base_install_order installOrder\n" +
        "inner join base_sale_order saleOrder on saleOrder.id = installOrder.sale_order_id and saleOrder.del_flag = 0\n" +
        "inner join base_product product on product.id = saleorder.product_id and product.del_flag = 0\n" +
        "inner join base_device device on device.id = product.device_id and device.del_flag = 0\n" +
        "inner join base_user salesMan on salesMan.id = saleOrder.sales_man_id and salesMan.del_flag = 0\n" +
        "inner join base_company salesManCompany on salesManCompany.id = salesMan.company_id and salesManCompany.del_flag = 0\n" +
        "inner join sys_dict_data saleChannelDic on saleChannelDic.dict_value = salesManCompany.channel_type and saleChannelDic.dict_type = 'dict_channel_type'\n" +
        "inner join base_user installMan on installMan.id = installOrder.install_man_id and installMan.del_flag = 0\n" +
        "inner join base_company installManCompany on installManCompany.id = salesMan.company_id and installManCompany.del_flag = 0\n" +
        "inner join sys_dict_data installChannelDic on installChannelDic.dict_value = installManCompany.channel_type and installChannelDic.dict_type = 'dict_channel_type'\n" +
        "${ew.customSqlSegment}" +
        "</script>")
    public Page<BaseFilingsVo> getFilingPageList(Page Page, @Param(Constants.WRAPPER) QueryWrapper<BaseFilings> queryWrapper);

    @Select("<script>" +
        "select \n" +
        "	saleOrder.id as saleOrderId,\n" +
        "	installOrder.id as installOrderId,\n" +
        "	saleOrder.last_name as customer_name,\n" +
        "	saleOrder.phone as customer_phone,\n" +
        "	installOrder.car_no as car_no,\n" +
        "	device.device_name as device_name,\n" +
        "	device.device_model as device_model,\n" +
        "	product.product_name as product_name,\n" +
        "	saleChannelDic.dict_label as sale_channel_type_name,\n" +
        "	salesManCompany.company_name as sale_channel_name,\n" +
        "	salesMan.real_name as sales_man_name,\n" +
        "	installChannelDic.dict_label as install_channel_type_name,\n" +
        "	installManCompany.company_name as install_channel_name,\n" +
        "	installMan.real_name as install_man_name,\n" +
        "	installOrder.imei as imei,\n" +
        "	installOrder.online_time as online_time,\n" +
        "	installOrder.last_online_time as last_online_time,\n" +
        "	installOrder.active_time as active_time,\n" +
        "	installOrder.verify_status as verify_status,\n" +
        "	installOrder.verify_time as verify_time,\n" +
        "	installOrder.review_status as review_status,\n" +
        "	installOrder.review_time as review_time,\n" +
        "	installOrder.check_status as check_status,\n" +
        "	installOrder.check_time as check_time\n" +
        "from \n" +
        "base_install_order installOrder\n" +
        "inner join base_sale_order saleOrder on saleOrder.id = installOrder.sale_order_id and saleOrder.del_flag = 0\n" +
        "inner join base_product product on product.id = saleorder.product_id and product.del_flag = 0\n" +
        "inner join base_device device on device.id = product.device_id and device.del_flag = 0\n" +
        "inner join base_user salesMan on salesMan.id = saleOrder.sales_man_id and salesMan.del_flag = 0\n" +
        "inner join base_company salesManCompany on salesManCompany.id = salesMan.company_id and salesManCompany.del_flag = 0\n" +
        "inner join sys_dict_data saleChannelDic on saleChannelDic.dict_value = salesManCompany.channel_type and saleChannelDic.dict_type = 'dict_channel_type'\n" +
        "inner join base_user installMan on installMan.id = installOrder.install_man_id and installMan.del_flag = 0\n" +
        "inner join base_company installManCompany on installManCompany.id = salesMan.company_id and installManCompany.del_flag = 0\n" +
        "inner join sys_dict_data installChannelDic on installChannelDic.dict_value = installManCompany.channel_type and installChannelDic.dict_type = 'dict_channel_type'\n" +
        "${ew.customSqlSegment}" +
        "</script>")
    public List<BaseFilingsVo> getFilingList(@Param(Constants.WRAPPER) QueryWrapper<BaseFilings> queryWrapper);
}
